﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Windows.Forms;

    public class clsCanTruChiTiet
    {
        private double mChenhLechTyGia = 0.0;
        private string mDienGiai = "";
        private string mDienGiaiKhac = "";
        private string mKhoa = "";
        private string mKhoaCanTru = "";
        private string mKhoaChungTuDeCanTru = "";
        private string mKhoaDoiTuong = "";
        private string mKhoaTaiKhoanCo = "";
        private string mLoaiCanTru = "";
        private string mLoaiTien = "";
        private string mNgayChungTuDeCanTru = "";
        private string mNguonNhap = "";
        private string mSoChungTuDeCanTru = "";
        private double mSoTienCanTru = 0.0;
        private double mSoTienCanTruNT = 0.0;
        private double mSoTienChungTu = 0.0;
        private double mSoTienChungTuNT = 0.0;
        private double mSoTienConLai = 0.0;
        private double mSoTienConLaiNT = 0.0;
        private double mSoTienLe = 0.0;
        private double mSoTienLeNT = 0.0;
        private double mTyGia = 0.0;
        private double mTyGiaDeCanTru = 0.0;

        public void ClearTemp(string pKeyTable)
        {
            string commandText = "DELETE FROM GL_CanTruChiTietTmp WHERE KhoaCanTru = '" + pKeyTable.Trim() + "'";
            DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
        }

        public DataTable GetListByKhoaCanTru(string pKhoaCanTru)
        {
            DataTable table;
            try
            {
                string commandText = "SELECT CT.KHOA, CT.KHOACHUNGTUDECANTRU, CT.SOCHUNGTUDECANTRU, CT.NGAYCHUNGTUDECANTRU, CT.KHOADOITUONG,           DT.MA MADOITUONG, DT.TENVIET TENDOITUONG, CT.KHOATAIKHOANCO, TK.SOTAIKHOAN, TK.TENVIET TENTAIKHOAN,           CT.LOAITIEN, CT.TYGIA, CT.SOTIENCHUNGTUNT, CT.SOTIENCHUNGTU, CT.SOTIENCANTRUNT, CT.SOTIENCANTRU,           CT.SOTIENCONLAINT, CT.SOTIENCONLAI, CT.TYGIADECANTRU, CT.CHENHLECHTYGIA, CT.SOTIENLENT, CT.SOTIENLE,           CT.DIENGIAI, CT.DIENGIAIKHAC,           CASE LOAICANTRU           WHEN 'A/R' THEN  N'Chứng từ b\x00e1n h\x00e0ng'           WHEN 'A/P(-)' THEN N'Chứng từ chi tiền thừa'           ELSE N'Trả trước người b\x00e1n' END TENLOAICANTRU, NGUONNHAP, LOAICANTRU  FROM GL_CANTRUCHITIET CT  LEFT JOIN DM_DOITUONG DT ON CT.KHOADOITUONG = DT.KHOA  LEFT JOIN DM_TAIKHOAN TK ON CT.KHOATAIKHOANCO = TK.KHOA  WHERE KHOACANTRU = '" + pKhoaCanTru + "' ";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public bool Load(string pKhoa)
        {
            bool flag=false;
            try
            {
                string commandText = "SELECT * FROM GL_CanTruChiTiet WHERE Khoa = '" + pKhoa + "'";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
                if (dataReader.Read())
                {
                    this.mKhoa = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mKhoaCanTru = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mLoaiCanTru = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mNguonNhap = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mKhoaChungTuDeCanTru = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.mSoChungTuDeCanTru = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mNgayChungTuDeCanTru = Conversions.ToString(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDoiTuong = Conversions.ToString(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTaiKhoanCo = Conversions.ToString(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetString));
                    this.mLoaiTien = Conversions.ToString(modGeneral.GetValue(dataReader, 9, modGeneral.typeOfColumn.GetString));
                    this.mTyGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 10, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoTienChungTuNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 11, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoTienChungTu = Conversions.ToDouble(modGeneral.GetValue(dataReader, 12, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoTienCanTruNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 13, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoTienCanTru = Conversions.ToDouble(modGeneral.GetValue(dataReader, 14, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoTienConLaiNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 15, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoTienConLai = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x10, modGeneral.typeOfColumn.GetDecimal));
                    this.mTyGiaDeCanTru = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x11, modGeneral.typeOfColumn.GetDecimal));
                    this.mChenhLechTyGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x12, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoTienLeNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x13, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoTienLe = Conversions.ToDouble(modGeneral.GetValue(dataReader, 20, modGeneral.typeOfColumn.GetDecimal));
                    this.mDienGiai = Conversions.ToString(modGeneral.GetValue(dataReader, 0x15, modGeneral.typeOfColumn.GetString));
                    this.mDienGiaiKhac = Conversions.ToString(modGeneral.GetValue(dataReader, 0x16, modGeneral.typeOfColumn.GetString));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Save()
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[0x17];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, this.mKhoa);
                commandParameters[1] = DBHelper.createParameter("@KhoaCanTru", DbType.Int64, ParameterDirection.Input, this.mKhoaCanTru);
                commandParameters[2] = DBHelper.createParameter("@LoaiCanTru", DbType.Int64, ParameterDirection.Input, this.mLoaiCanTru);
                commandParameters[3] = DBHelper.createParameter("@NguonNhap", DbType.Int64, ParameterDirection.Input, this.mNguonNhap);
                commandParameters[4] = DBHelper.createParameter("@KhoaChungTuDeCanTru", DbType.Int64, ParameterDirection.Input, this.mKhoaChungTuDeCanTru);
                commandParameters[5] = DBHelper.createParameter("@SoChungTuDeCanTru", DbType.Int64, ParameterDirection.Input, this.mSoChungTuDeCanTru);
                commandParameters[6] = DBHelper.createParameter("@NgayChungTuDeCanTru", DbType.Int64, ParameterDirection.Input, this.mNgayChungTuDeCanTru);
                commandParameters[7] = DBHelper.createParameter("@KhoaDoiTuong", DbType.Int64, ParameterDirection.Input, this.mKhoaDoiTuong);
                commandParameters[8] = DBHelper.createParameter("@KhoaTaiKhoanCo", DbType.Int64, ParameterDirection.Input, this.mKhoaTaiKhoanCo);
                commandParameters[9] = DBHelper.createParameter("@LoaiTien", DbType.Int64, ParameterDirection.Input, this.mLoaiTien);
                commandParameters[10] = DBHelper.createParameter("@TyGia", DbType.Date, ParameterDirection.Input, this.mTyGia);
                commandParameters[11] = DBHelper.createParameter("@SoTienChungTuNT", DbType.Date, ParameterDirection.Input, this.mSoTienChungTuNT);
                commandParameters[12] = DBHelper.createParameter("@SoTienChungTu", DbType.Date, ParameterDirection.Input, this.mSoTienChungTu);
                commandParameters[13] = DBHelper.createParameter("@SoTienCanTruNT", DbType.Date, ParameterDirection.Input, this.mSoTienCanTruNT);
                commandParameters[14] = DBHelper.createParameter("@SoTienCanTru", DbType.Date, ParameterDirection.Input, this.mSoTienCanTru);
                commandParameters[15] = DBHelper.createParameter("@SoTienConLaiNT", DbType.Date, ParameterDirection.Input, this.mSoTienConLaiNT);
                commandParameters[0x10] = DBHelper.createParameter("@SoTienConLai", DbType.Date, ParameterDirection.Input, this.mSoTienConLai);
                commandParameters[0x11] = DBHelper.createParameter("@TyGiaDeCanTru", DbType.Date, ParameterDirection.Input, this.mTyGiaDeCanTru);
                commandParameters[0x12] = DBHelper.createParameter("@ChenhLechTyGia", DbType.Date, ParameterDirection.Input, this.mChenhLechTyGia);
                commandParameters[0x13] = DBHelper.createParameter("@SoTienLeNT", DbType.Date, ParameterDirection.Input, this.mSoTienLeNT);
                commandParameters[20] = DBHelper.createParameter("@SoTienLe", DbType.Date, ParameterDirection.Input, this.mSoTienLe);
                commandParameters[0x15] = DBHelper.createParameter("@DienGiai", DbType.Int64, ParameterDirection.Input, this.mDienGiai);
                commandParameters[0x16] = DBHelper.createParameter("@DienGiaiKhac", DbType.Int64, ParameterDirection.Input, this.mDienGiaiKhac);
                if (DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_sp_CanTruChiTiet", commandParameters) > 0)
                {
                    return true;
                }
                flag = false;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public double ChenhLechTyGia
        {
            get
            {
                return this.mChenhLechTyGia;
            }
            set
            {
                this.mChenhLechTyGia = value;
            }
        }

        public string DienGiai
        {
            get
            {
                return this.mDienGiai;
            }
            set
            {
                this.mDienGiai = value;
            }
        }

        public string DienGiaiKhac
        {
            get
            {
                return this.mDienGiaiKhac;
            }
            set
            {
                this.mDienGiaiKhac = value;
            }
        }

        public string Khoa
        {
            get
            {
                return this.mKhoa;
            }
            set
            {
                this.mKhoa = value;
            }
        }

        public string KhoaCanTru
        {
            get
            {
                return this.mKhoaCanTru;
            }
            set
            {
                this.mKhoaCanTru = value;
            }
        }

        public string KhoaChungTuDeCanTru
        {
            get
            {
                return this.mKhoaChungTuDeCanTru;
            }
            set
            {
                this.mKhoaChungTuDeCanTru = value;
            }
        }

        public string KhoaDoiTuong
        {
            get
            {
                return this.mKhoaDoiTuong;
            }
            set
            {
                this.mKhoaDoiTuong = value;
            }
        }

        public string KhoaTaiKhoanCo
        {
            get
            {
                return this.mKhoaTaiKhoanCo;
            }
            set
            {
                this.mKhoaTaiKhoanCo = value;
            }
        }

        public string LoaiCanTru
        {
            get
            {
                return this.mLoaiCanTru;
            }
            set
            {
                this.mLoaiCanTru = value;
            }
        }

        public string LoaiTien
        {
            get
            {
                return this.mLoaiTien;
            }
            set
            {
                this.mLoaiTien = value;
            }
        }

        public string NgayChungTuDeCanTru
        {
            get
            {
                return this.mNgayChungTuDeCanTru;
            }
            set
            {
                this.mNgayChungTuDeCanTru = value;
            }
        }

        public string NguonNhap
        {
            get
            {
                return this.mNguonNhap;
            }
            set
            {
                this.mNguonNhap = value;
            }
        }

        public string SoChungTuDeCanTru
        {
            get
            {
                return this.mSoChungTuDeCanTru;
            }
            set
            {
                this.mSoChungTuDeCanTru = value;
            }
        }

        public double SoTienCanTru
        {
            get
            {
                return this.mSoTienCanTru;
            }
            set
            {
                this.mSoTienCanTru = value;
            }
        }

        public double SoTienCanTruNT
        {
            get
            {
                return this.mSoTienCanTruNT;
            }
            set
            {
                this.mSoTienCanTruNT = value;
            }
        }

        public double SoTienChungTu
        {
            get
            {
                return this.mSoTienChungTu;
            }
            set
            {
                this.mSoTienChungTu = value;
            }
        }

        public double SoTienChungTuNT
        {
            get
            {
                return this.mSoTienChungTuNT;
            }
            set
            {
                this.mSoTienChungTuNT = value;
            }
        }

        public double SoTienConLai
        {
            get
            {
                return this.mSoTienConLai;
            }
            set
            {
                this.mSoTienConLai = value;
            }
        }

        public double SoTienConLaiNT
        {
            get
            {
                return this.mSoTienConLaiNT;
            }
            set
            {
                this.mSoTienConLaiNT = value;
            }
        }

        public double SoTienLe
        {
            get
            {
                return this.mSoTienLe;
            }
            set
            {
                this.mSoTienLe = value;
            }
        }

        public double SoTienLeNT
        {
            get
            {
                return this.mSoTienLeNT;
            }
            set
            {
                this.mSoTienLeNT = value;
            }
        }

        public double TyGia
        {
            get
            {
                return this.mTyGia;
            }
            set
            {
                this.mTyGia = value;
            }
        }

        public double TyGiaDeCanTru
        {
            get
            {
                return this.mTyGiaDeCanTru;
            }
            set
            {
                this.mTyGiaDeCanTru = value;
            }
        }
    }
}

